package cn.dkdoo.mongodb.controller;

import cn.dkdoo.bean.vo.AddRequest;
import cn.dkdoo.bean.vo.RemoveRequest;
import cn.dkdoo.bean.vo.UpdateMultiRequest;
import cn.dkdoo.bean.vo.UpdateRequest;
import cn.dkdoo.mongodb.service.MongodbService;
import cn.dkdoo.utils.entity.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author nicky
 * @date 2021/5/12 下午5:23
 */
@RestController
@RequestMapping("/mongodb")
public class MongodbController {

    @Autowired
    private MongodbService mongodbService;

    @RequestMapping(value = "", method = RequestMethod.POST)
    public BaseResponse add(@RequestBody AddRequest request) {
        BaseResponse response = mongodbService.add(request);
        return response;
    }

    @RequestMapping(value = "", method = RequestMethod.PUT)
    public BaseResponse update(@RequestBody UpdateRequest request) {
        BaseResponse response = mongodbService.update(request);
        return response;
    }

    @RequestMapping(value = "self", method = RequestMethod.PUT)
    public BaseResponse updateSelf(@RequestBody UpdateRequest request) {
        BaseResponse response = mongodbService.updateSelf(request);
        return response;
    }

    @RequestMapping(value = "multi", method = RequestMethod.PUT)
    public BaseResponse updateMulti(@RequestBody UpdateMultiRequest request) {
        BaseResponse response = mongodbService.updateMulti(request);
        return response;
    }

    @RequestMapping(value = "", method = RequestMethod.DELETE)
    public BaseResponse remove(@RequestBody RemoveRequest request) {
        BaseResponse response = mongodbService.remove(request);
        return response;
    }
}
